package cn.com.w.jdk8.demo.service;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;

public class IdsListService {


    public static <T> void getIds(Supplier<List<T>> supplier){
        do {
            List<T> recordList = supplier.get();
            if (CollectionUtils.isEmpty(recordList)) {
                break;
            }
            System.out.println(JSONObject.toJSONString(recordList));
        } while (true);
    }


    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);list.add(2);list.add(3);list.add(4);
        // 游标查询线索
        final AtomicInteger cursor = new AtomicInteger(0);
        getIds(() -> {
            int i = cursor.get();
            List<Integer> list1 = Lists.newArrayList(list.get(i));
            cursor.incrementAndGet();
            return list1;
        });
    }
}
